package com.jinduplan.planmanager.mvp.model

import com.cxz.kotlin.baselibs.bean.BaseBean
import com.cxz.kotlin.baselibs.mvp.BaseModel
import com.cxz.kotlin.baselibs.utils.GsonHelper
import com.cxz.kotlin.baselibs.utils.Preference
import com.jinduplan.planmanager.bean.*
import com.jinduplan.planmanager.constant.Constant
import com.jinduplan.planmanager.http.MainRetrofit
import com.jinduplan.planmanager.mvp.contract.ClockInContract
import io.reactivex.rxjava3.core.Observable

/**
 * @author chenxz
 * @date 2018/12/1
 * @desc
 */
class ClockInModel : BaseModel(), ClockInContract.Model {
    var project_addr: String by Preference(Constant.PROJECT_ADDR, "")

    override fun clockIn(
        file: String,
        longtitue: String,
        latitue: String,
        projectid: String
    ): Observable<HttpResult<ClockinSuccess>> {
        return MainRetrofit.service.clockin(GsonHelper.getRequestBoby(arrayListOf("project_id","images","lat","lon","address_detail"),
            arrayListOf(projectid,file,latitue.toString(),longtitue.toString(),project_addr)))

    }

    override fun uploadClockInPic(file: String): Observable<HttpResult<PicUploadSuccess>> {
        return MainRetrofit.service.uploadClockinPic(GsonHelper.uploadSinglePart(file,"images"))
    }

    override fun postProjectLocation(
        project_id: String,
        addr_name: String,
        address: String,
        lat: String,
        lon: String,
        building_id: String,
        province: String,
        city: String,
        county: String,
        address_detail: String
    ): Observable<HttpResult<UploadProjectLocation>> {

        return MainRetrofit.service.location(GsonHelper.getRequestBoby(arrayListOf("project_id","addr_name","address","lat","lon"
        ,"building_id","province","city","county","address_detail"),
            arrayListOf(project_id,addr_name,address,lat,lon,building_id,province,city,county,address_detail)))
    }


    override fun getProjectUploadDetailList(project_id: Int): Observable<HttpResult<BuildingNameBean>> {
        val map = HashMap<String,Int>()
        map["project_id"] = project_id
        map["page"] = 1
        map["limit"] = 999
        return MainRetrofit.service.getBuild(GsonHelper.getRequestIntBoby(map))
    }

}